package com.linxi.handy.component.dialog;

import com.linxi.handy.component.control.HomeControl;
import com.linxi.handy.component.view.Tableview;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author user
 */
public class SetNullDialog extends JDialog {

    JTextField tf1 = new JTextField();
    JButton b = new JButton("更 改");

    public SetNullDialog(JFrame f) {
        super(f, false);
        this.setLayout(null);
        this.add(tf1);
        this.add(b);

        b.addActionListener(new ButtonProcessListener());

        tf1.setBounds(30, 15, 160, 30);
        b.setBounds(200, 15, 60, 30);
        //设置一些属性
        b.setBackground(new Color(245, 245, 245));
        tf1.setText(Tableview.control);

        this.setSize(300, 100);
        //将窗体设置在屏幕中间
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension size = this.getSize();
        int x = (screenSize.width - size.width) / 2;
        int y = (screenSize.height - size.height) / 2;
        this.setLocation(x, y);
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        this.setModal(true);
        this.setVisible(true);
    }

    class ButtonProcessListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == b) {
                if (Tableview.control.equals(tf1.getText())) {
                    return;
                }
                Tableview.control = tf1.getText();
                HomeControl.ft.removeAll();
                HomeControl.ft.add(HomeControl.ft.mainTextArea, "Welcome");
                HomeControl.fdi.setText(Tableview.control + "被用作表示空值", null);
                //更改成功就关闭窗口
                dispose();
            }
        }

    }
}
